package com.lcy.smartcity.service;

import com.lcy.smartcity.dto.BuildingsDTO;
import com.lcy.smartcity.entity.Buildings;
import com.lcy.smartcity.mapper.BuildingsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class BuildingsService {

    @Autowired
    private BuildingsMapper buildingsMapper;

    public Optional<Buildings> findById(Integer id) {
        return Optional.ofNullable(buildingsMapper.findById(id));
    }

    public List<Buildings> SearchByName(String name) {
        return buildingsMapper.findByNameContainingIgnoreCase(name);
    }

    public List<Buildings> SearchHotelByName(String name) {
        return buildingsMapper.findHotelByNameContainingIgnoreCase(name);
    }


    //PostGIS空间查询逻辑
    public List<Buildings> findBuildingsWithinDistance(Double longitudeX, Double latitudeY, Double distance) {
        // 使用PostGIS的空间函数进行查询
        // ST_DWithin函数检查两个地理点之间的距离是否小于或等于指定的距离(单位：米)
        return buildingsMapper.findBuildingsWithinDistance(longitudeX, latitudeY, distance);
    }
}
